import QtQuick 2.2
import Control.Class 1.0
import "../mainmenu"

Rectangle {

    property var titleList: new Array
    signal onclick(string title)
   // color: "red"

    Component.onCompleted: {
        instructpanel.settitleList("select distinct Type from Instructions")
        for(var i=0; i< instructpanel.strCount(); i++)
        {
            grid.textnameList.push(instructpanel.getTitle(i))
            console.log(grid.textnameList[i] + "   " )
        }
    }

    function searchTitle(title){
        for(var i= 0; i< 20; i++)
        {
//            if(grid.children[i].backcolor === "#00ACB6")
//                grid.children[i].backcolor = "white"
//            if(grid.children[i].textname === title)
//                grid.children[i].backcolor = "#00ACB6"
            if(grid.getItem(i).backcolor === "#00ACB6")
                grid.getItem(i).backcolor = "white"
            if(grid.getItem(i).textname === title)
                grid.getItem(i).backcolor = "#00ACB6"
        }
    }

    function initInstructClass()
    {
        instructpanel.settitleList("select distinct Type from Instructions");
        for(var i=0; i < instructpanel.strCount(); i++)
        {
            titleList.push(instructpanel.getTitle(i))
            grid.textnameList.push(instructpanel.getTitle(i))
        }
        grid.resetText()
    }
    InstructionPanel{
        id: instructpanel
    }

//    Grid{
//        id: grid
//        columns: 2
//        columnSpacing: 5;
//        InstructItem{textname: /*instructpanel.getTitle(0)*/qsTr("Common"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*instructpanel.getTitle(1)*/qsTr("Prog.Flow"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[2]*/qsTr("Various"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[3]*/qsTr("Settings"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[4]*/qsTr("Motion&Proc."); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[5]*/qsTr("I/O"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[6]*/qsTr("Communicate"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[7]*/qsTr("Interrupts"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[8]*/qsTr("Error Rec."); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[9]*/qsTr("System&Time"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[10]*/qsTr("Mathematics"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[11]*/qsTr("MotionSetAdv"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[12]*/qsTr("Motion Adv."); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[13]*/qsTr("Ext.Computer"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[14]*/qsTr("MultiTasking&MultiMove"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[15]*/qsTr("RAPIDsupport"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[16]*/qsTr("Calib&Service"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[17]*/qsTr("M.C 1"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[18]*/qsTr("M.C 2"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}
//        InstructItem{textname: /*titleList[19]*/qsTr("M.C 3"); width: parent.width/2; height: (parent.height -20)/10; textVLocate: 1; fontsize: 18}

//        anchors{
//            top: parent.top; bottom: parent.bottom; left: parent.left; right: parent.right;
//            topMargin: 10; leftMargin: 3;
//        }
//    }
    ModelPanel{
        id: grid
        rowCount: 10; columnCount: 2; rowspacing: 5
        itemBorderColor: "white"
        anchors{
            top: parent.top; bottom: parent.bottom; left: parent.left; right: parent.right;
            /*topMargin: 10;*/ leftMargin: 3;
        }
    }

    MouseArea{
        id: area
        onClicked: {
            console.log(qsTr("clicked the InstructClassPanel"))
//           // var point1 = Qt.point(mouse.x, mouse.y)
//            //point1 = mapToItem(parent, point1.x, point1.y)
//            //console.log(point1.x+","+point1.y + "\n"+ grid.childAt(point1.x, point1.y)+"\n"+area)
//            console.log(grid.childAt(mouse.x, mouse.y).textname)
//            searchTitle(grid.childAt(mouse.x, mouse.y).textname)
//            onclick(grid.childAt(mouse.x, mouse.y-10).textname)
            console.log(grid.getItemfromPoint(mouse.x, mouse.y))
            searchTitle(grid.getItemfromPoint(mouse.x, mouse.y))
            onclick(grid.getItemfromPoint(mouse.x, mouse.y))
        }
        anchors.fill: parent
    }
}
